<?
ob_start();
session_start();
include("../conf/config.php");
include("../conf/database.php");
include("../conf/tools.php");
$selected_members=$_GET["sel"];
$curTime=getIndianDateTime();
//$member_list=explode(",",$selected_members);

$member_list = qry_data("select distinct registrant_id,full_name,email_id,reg_password,center_incharge_name  from bkitc_profiles where rec_status=1 and registrant_id in ($selected_members) and email_id!=''");
$emailListFinal="";
$mv=(int)$_REQUEST["mv"];

if($mv==1){

foreach($member_list as  $member){

	$arr_data["program_id"]=$_REQUEST["prg_id"];
	$arr_data["member_id"]=$member["registrant_id"];
	$arr_data["rec_status"]=1;
	$prg_mem_id=insert_qry("bkitc_program_members",$arr_data);
	qry_data("update bkitc_program_members set invited_date='".$curTime."' where program_id=".$_REQUEST["prg_id"]." and prg_mem_id=".$prg_mem_id);
	
	$prgInfo=@array_pop(qry_data("select prg_title from bkitc_programs where prg_id=".$_REQUEST["prg_id"]));
	
	$toEmailId=$member["email_id"];
	$fullname=$member["full_name"];

	$eventInfo["full_name"]=$fullname;
	$eventInfo["email_id"]=$toEmailId;
	$eventInfo["event_name"]=$prgInfo["prg_title"];

	qry_data("update bkitc_invite_list_mem set inv_status=1 where mem_id=".$arr_data["member_id"]." and list_id=".$_GET["list_id"]);


	if(send_event_invite($eventInfo)){
		writeLog("Program Invitation Sent to ".$fullname." to email id ". $toEmailId. " : by".$_SESSION["admin_username"]);
		$emailList.=$toEmailId."\n".$emailList;
	}
	
}
echo "Selected Members Invited Successfully";
}else if($mv==2){


foreach($member_list as  $member){

$toEmailId=$member["email_id"];
$memberId=$member["registrant_id"];
$password=$member["reg_password"];
$fullname=$member["full_name"];

if(notify_resume_request($member)){
	writeLog("Resume Upload Request  Sent to ".$fullname." to email id ". $toEmailId. " : by".$_SESSION["admin_username"]);
	$emailListFinal.=$toEmailId."\n";

}
else
{	
	writeLog("failed to send Resume Upload Request   for ".$fullname." to email id ". $toEmailId. " : by ".$_SESSION["admin_username"]);
	$emailListFailed.=$toEmailId."\n";
}

}
if($emailListFinal!="") echo "Notification  Sent Successfully for the following Members.\n".$emailListFinal;
if($emailListFailed!="") echo "\n\nNotification  failed to send for the following email id.\n".$emailListFailed;



}else if($mv==-1){


$member_list = qry_data("select distinct registrant_id,full_name,email_id,reg_password,center_incharge_name  from bkitc_profiles where rec_status=1 and resume_filename='' and email_id!=''");

foreach($member_list as  $member){

$toEmailId=$member["email_id"];
$memberId=$member["registrant_id"];
$password=$member["reg_password"];
$fullname=$member["full_name"];

if(notify_resume_request($member)){
	writeLog("Resume Upload Request  Sent to ".$fullname." to email id ". $toEmailId. " : by".$_SESSION["admin_username"]);
	$emailListFinal.=$toEmailId."\n";

}
else
{	
	writeLog("failed to send Resume Upload Request   for ".$fullname." to email id ". $toEmailId. " : by ".$_SESSION["admin_username"]);
	$emailListFailed.=$toEmailId."\n";
}

}
if($emailListFinal!="") echo "Notification  Sent Successfully for the following Members.\n".$emailListFinal;
if($emailListFailed!="") echo "\n\nNotification  failed to send for the following email id.\n".$emailListFailed;


}
else{




foreach($member_list as  $member){

$toEmailId=$member["email_id"];
$memberId=$member["registrant_id"];
$password=$member["reg_password"];
$fullname=$member["full_name"];

if(notify_login_new($member)){
	writeLog("Login Info Sent to ".$fullname." to email id ". $toEmailId. " : by".$_SESSION["admin_username"]);
	$emailListFinal.=$toEmailId."\n";

}
else
{	
	writeLog("failed to send Login Info for ".$fullname." to email id ". $toEmailId. " : by ".$_SESSION["admin_username"]);
	$emailListFailed.=$toEmailId."\n";
}

}
if($emailListFinal!="") echo "Notification  Sent Successfully for the following Members.\n".$emailListFinal;
if($emailListFailed!="") echo "\n\nNotification  failed to send for the following email id.\n".$emailListFailed;


}
?>
